<template>
  <div class='container'>
    <!-- 修改弹框 -->
    <el-dialog title="添加文章" :visible="addArcitcalDialog" width="40%" @close="resetEditArt">
      <!-- 表单区域 -->
      <el-form :model="addArcical" :rules="rules"  ref="editArticlesForm" label-width="80px" class="demo-ruleForm">
        <el-form-item label="文章标题" prop="title" class="elform">
          <el-input v-model="addArcical.title"  placeholder="请输入文章标签"></el-input>
        </el-form-item>
        <el-form-item label="文章标题" prop="articleBody" class="elform">
          <quill-editor v-model="addArcical.articleBody" style="margin-left: 0px;"  ref="Editor"> </quill-editor>
        </el-form-item>
        <el-form-item label="视频地址" class="elform">
          <el-input v-model="addArcical.videoURL" placeholder="请输入视频地址"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="resetEditArt">取 消</el-button>
        <el-button type="primary" @click="confimrArtical" >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import { quillEditor } from 'vue-quill-editor'
// 引入文章添加方法
import { add as addArtical } from '@/api/hmmm/articles'
export default {
  components: {
    quillEditor
  },
  data () {
    return {
      // 添加文章的表单
      addArcical: {
        title: null,
        articleBody: null,
        videoURL: null
      },
      rules: {
        title: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 18, message: '长度在 3 到 18 个字符', trigger: 'blur' }
        ],
        articleBody: [
          { required: true, message: '请输入活动名称', trigger: 'blur' }
        ]
      }
    }
  },
  props: {
    addArcitcalDialog: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // 关闭弹框
    resetEditArt () {
      this.addArcical = {
        title: null,
        articleBody: null,
        videoURL: null
      }
      this.$emit('update:addArcitcalDialog', false)
    },
    // 添加面试技巧
    confimrArtical () {
      // 点击确定之后先进行校验
      this.$refs.editArticlesForm.validate()
        .then(() => {
          return addArtical(this.addArcical)
        })
        .then(() => {
          // 提示用户添加成功
          this.$message.success('添加成功')
          //  告诉父组件我的任务完成了
          this.resetEditArt()
          this.$emit('done')
        })
    }
  }

}
</script>

<style scoped lang='scss'></style>
